package com.ioudi.digu.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ioudi.digu.dao.MessageSelectorDAO;
import com.ioudi.digu.service.IMessageSelectorService;
import com.ioudi.digu.service.UserAwareService;
import com.ioudi.digu.vo.MessageSelector;

public class MessageSelectorService extends UserAwareService implements
		IMessageSelectorService
{
	private MessageSelectorDAO messageSelectorDAO;
	
	public MessageSelector getMessageSelecotr(String user)
	{
		Object selector = messageSelectorDAO.getObject(user);
		if(selector == null && user != null && user != "null")
		{
			selector = new MessageSelector(user);
			messageSelectorDAO.saveObject(selector);
		}
		return (MessageSelector)selector;
	}
	
	public boolean updateMessageSelector(Map change)
	{
		String user = getUser();
		if(user == null)
		{
			return false;
		}
		return messageSelectorDAO.updateObject(user, change) != null;
	}
	
	public Object findProperty(String user, String fieldName)
	{
		Map condition = new HashMap();
		condition.put("user", user);
		List list =  messageSelectorDAO.findFields(fieldName, condition);
		return list != null ? list.get(0) : null;
	}
	
	public MessageSelectorDAO getMessageSelectorDAO()
	{
		return messageSelectorDAO;
	}
	public void setMessageSelectorDAO(MessageSelectorDAO messageSelectorDAO)
	{
		this.messageSelectorDAO = messageSelectorDAO;
	}

	

}
